<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/base.jsp"%>
<%@ include file="/module/taglibs.jsp"%>
<%@ include file="/module/nocache.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>材料管理</title>
<%@ include file="/module/js.jsp"%>
</head>
<body>
	<form action="#" name="Form" id="Form" method="post">
	   <input type="hidden" name="directoryId" id="directoryId"  value="${directoryId}"/> 
		<input type="hidden" name="idList" id="idList"/>
		<input type="hidden" name="level" id="level"  value="${level}"/> 
	    <input type="hidden" name="projectId" id="projectId"  value="${projectId}"/> 
		<table cellpadding="1" cellspacing="1" border="0">
			<tr>
				<td><input type="button" id="btnQuery" value="查询"
					class="inputButton" /></td>
					   <kl:permission permisstionList="${permisstionList}" currentUser="${_login_console_user}" currentCatalogId="<%=CatalogUtils.getCatalogId(\"OF_ZLTS_CLGL\")%>" key="add">	
				<td><input type="button" id="btnAdd"  value="添 加 "
					class="inputButton" /></td>
					</kl:permission>
					   <kl:permission permisstionList="${permisstionList}" currentUser="${_login_console_user}" currentCatalogId="<%=CatalogUtils.getCatalogId(\"OF_ZLTS_CLGL\")%>" key="delete">	
				<td><input type="button" id="btnDelete" value="删除"
					 class="inputButton"/></td>
					 </kl:permission>
			    <td><input type="button" id="btnBreak" value="返回"
					 class="inputButton"/></td>		
			</tr>
		</table>
	   <table cellpadding="1" cellspacing="1">
			<tr>
				<td>主题：</td>
				<td><input type="text" name="title" id="title"  autocomplete="off" class="inputText" /></td>
			</tr>
		</table>	
		
	<%-- 	<table id="dg" class="easyui-datagrid "  style="width:100%;"
		data-options="pagination:true,collapsible:true,url:'${basePath}/projectmaterial/List',method:'post',remoteSort:true"> --%>
        <table id="dg"  style="width:100%;"
		data-options="pagination:true,collapsible:true,url:'${basePath}/projectmaterial/List?directoryId=${directoryId}&level=${level}',method:'post',remoteSort:true,striped:true"> 
		<thead>
			<tr>
				<th data-options="field:'projectMaterialId',checkbox:true,width:60,align:'left'"></th>
				<th data-options="field:'state',sortable:true,nowrap:true,width:300,align:'left',formatter: formstates">状态</th>
			    <th data-options="field:'projectName',sortable:true,nowrap:true,width:300,align:'left'">项目名称</th>
				<th data-options="field:'directoryName',sortable:true,nowrap:true,width:300,align:'left'">目录名称</th>
				<th data-options="field:'title',sortable:true,nowrap:true,width:300,align:'left',formatter: formater">主题</th>
			    <th data-options="field:'date',sortable:true,nowrap:true,width:200,align:'left',formatter: formatDate">时间</th>
			    <th data-options="field:'type',sortable:true,nowrap:true,width:200,align:'left',formatter: formatType">文件类型</th>
			    <th data-options="field:'xm',sortable:true,nowrap:true,width:200,align:'left'">负责人</th>
			    <th data-options="field:'name',nowrap:true,width:300,align:'left',sortable:true">添加人</th>
			    <th data-options="field:'projectMaterialAddDate',sortable:true,nowrap:true,width:200,align:'left',formatter: formatDate">添加时间</th>
			</tr>
		</thead>
	</table>
	</form>
	
	
    
  
	
		 <script type="text/javascript">
		 
		   function formatDate(value){
		    	var date=new Date(value);
				var y = date.getFullYear();
				var m = date.getMonth()+ 1;
				var d = date.getDate();
				var h= date.getHours();       //获取当前小时数(0-23)
				var mm= date.getMinutes();     //获取当前分钟数(0-59)
				var s= date.getSeconds();     //获取当前秒数(0-59)
				return y +'-'+(m <10?('0'+ m):m)+'-'+(d <10?('0'+ d):d)+' :'+(h <10?('0'+ h):h)+':'+(mm <10?('0'+ mm):mm)+':'+(s <10?('0'+ s):s);
			}
	    
		 
		   function formstates(value,row, index){
		    	if(value==0){
		    		 return  value="保存"
		    	}else if(value==1){
		    		 return value="已提交"
		    	}else if(value==2){
		    		 return value="退回"
		    	}
			}    
		   
		   
		   function formatType(value,row, index){
		    	if(value==1){
		    		 return  value="上交"
		    	}else if(value==2){
		    		 return value="个人"
		    	}
			}    
		   
		   
		   
		     function formater(value, row, index) {
		        return "<a href='${basePath}/projectmaterial/details?id=" + row.projectMaterialId +"&directoryId=${directoryId}&projectId=${projectId}&level=${level}'>" + value + "</a>";
		        // return "<a href='${basePath}/projectmaterial/details?id=" + row.projectMaterialId+"&directoryId="+${directoryId}+"'>" + value + "</a>";
		       /*   return "<a href='${basePath}/projectmaterial/index?id=" + row.projectMaterialId+"'>" + value + "</a>"; */
	         }
		 
			$(document).ready(
							function() {
	                             $('#dg').datagrid({
								/*  onSortColumn :function(sort,order){
								   var _sort=sort;
								   var _order=order;
								   var options=$('#dg').datagrid('getPager').data("pagination").options;
								   var page=options.pageNumber;
								   var pageSize=options.pageSize;
								   window.setTimeout(function(){
									   $.post("${basePath}/projectmaterial/List",{orderFlag:_order,orderField:_sort,
										   title: $('#title').val(),
										   directoryId :$('#directoryId').val(),
									       level :$('#level').val()
									     
									    },
												function(data){
												  $('#dg').datagrid("loadData",data); 
											   });
											   },100);  
								   },
								   rowStyler: function(index,row){
								   },
								    */
								   onClickRow: function (rowIndex, rowData) {
						                 $(this).datagrid('unselectRow', rowIndex);
						            },
						            
								   onLoadSuccess: function(data){//加载完毕后获取所有的checkbox遍历
									                 if (data.rows.length > 0) {
									                    //循环判断操作为新增的不能选择
									                    var checkbox = $("input[type='checkbox']");

									                    for (var i = 0; i < data.rows.length; i++) {
									                        //根据operate让某些行不可选
									                        if (data.rows[i].cllogo == 0) {
										                                 $(checkbox.get(i+1)).remove();
										                            	//$("input[type='checkbox']")[i+1].remove();
										                               // $('#dg').datagrid('deleteRow',i);//选择该行 
									                                  // $("input[type='checkbox']")[i + 1].disabled = true;
									                                  //$("input[type='checkbox']")[i].remove();
									                        }
									                    }
									                }
												}
	                          });
	                             
	                 			
	                     		
								   $('#easyui-ck').click(function() {
									    var data = $("#dg").datagrid("getSelections");
					                    for (var i = 0; i < data.length; i++) {
					                        //根据states让某些行不可选
					                        if (data[i].cllogo ==0) {
						                            	//$("input[type='checkbox']")[i+1].remove();
						                                 $('#dg').datagrid('unselectRow',i);//选择该行 
						                                 $("#easyui-ck").attr('checked','checked'); 
					                                     // $("input[type='checkbox']")[i + 1].disabled = true;
					                        }
					                    }
									}); 		
								   
								//返回
								$('#btnBreak').click(function() {
									  //window.location.href = "${basePath}/directory/index?projectId="+${projectId};
									   window.location.href = "${basePath}/directory/index";
								});
								
								$('#btnAdd').click(function() {
									/*    window.location.href = "${basePath}/projectmaterial/addInInt"; */
								    /* 	 window.location.href = "${basePath}/projectmaterial/addInInt?directoryId="+${directoryId}; */
									 window.location.href = "${basePath}/projectmaterial/addInInt?directoryId="+${directoryId}+"&projectId=${projectId}&level=${level}";
								});
								
								//查询
								$('#btnQuery')
										.click(
												function() {
													$('#dg').datagrid('load',{
														title: $('#title').val(),
													    directoryId :$('#directoryId').val(),
												        level :$('#level').val()
													});
												});
								
								$('#btnDelete').click(function() {
						               $("#idList").val("");
										var count = 0;
										var idList = new Array();
									    var sels = $("#dg").datagrid("getSelections");
								    	for(var i in sels){
								    		idList.push(sels[i].projectMaterialId);
								    		count++;
								    	}
										
										if (count == 0) {
											layer.alert("您至少选择一条删除记录信息", {icon: 3});
											return false;
										}else{
											  layer.confirm("您是否删除当前选中数据信息", {icon: 3, title:'提示',skin:'layer-ext-moon'}, function(index){
												    $("#idList").val(idList);
												    document.Form.action = "${basePath}/projectmaterial/delete";
													document.Form.submit();
											  },function(index){
													layer.close(index);
											  });
										}
									});
								
								/* $('#btnUpdate').click(function() {
								    var count = 0;
									var id =null;
								    var sels = $("#dg").datagrid("getSelections");
							    	for(var i in sels){
							    		if (count == 1) {
											  layer.alert("只能允许选择一条编辑记录信息", {icon: 3});
											  return false;
										}
							    		id=sels[i].projectMaterialId;
							    		count++;
							    	}
									if (count == 0) {
										 layer.alert("请选择一条编辑记录信息", {icon: 3});
										 return false;
									}else{
										 window.location.href ="${basePath}/projectmaterial/updateToview?id="+id+"&directoryId="+${directoryId}+"&projectId="+${projectId};
										
										 window.location.href ="${basePath}/projectmaterial/updateToview?id="+id+"&directoryId="+${directoryId}+"&projectId="+${projectId};
									}
				             }); */
			
		         });
			
			
		 if("${msg}"!=""){
		       layer.alert("${msg}", {icon: 6});
		 } 
				
		</script>
</body>
</html>
